package com.zcxy360.sandtable.controller;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.zcxy360.sandtable.domain.Video;
import com.zcxy360.sandtable.service.VideoService;

/**
 * 视频接口
 * @author 盛亚辉
 *
 */
@RequestMapping("video")
@RestController
public class VideoController {
	
	@Autowired
	private VideoService videoService;

	/**
	 * 获取视频
	 * @param videoId 视频id
	 * @param deep 0代表基本数据,1代表扩展数据
	 * @return 视频对象
	 */
	@RequiresAuthentication
	@GetMapping("{videoId}")
	public Object getByVideoId(@PathVariable("videoId") Integer videoId,@RequestParam(defaultValue="0") Integer deep) {
		return  videoService.getByVideoId(videoId,deep);
	}
	
	/**
	 * 获取视频集合
	 * @param video 视频字段
	 * @param key 关键字
	 * @param orderByClause 排序规则
	 * @param sign 查询标识
	 * @param pageNum 页码
	 * @param pageSize 页数
	 * @param navigatePages 导航数
	 * @return 视频集合
	 */
	@RequiresRoles(value={"admin","manager","teacher"},logical=Logical.OR)
	@GetMapping
	public Object list(Video video,String key,String orderByClause, Integer sign,
			@RequestParam(defaultValue = "1") Integer pageNum,
			@RequestParam(defaultValue = "5") Integer pageSize,
			@RequestParam(defaultValue = "5") Integer navigatePages) {
		return videoService.list(video,key,orderByClause,sign,pageNum,pageSize,navigatePages);
	}
	
	/**
	 * 新增视频
	 * @param video 视频字段
	 * @param file 上传文件
	 * @return 视频对象
	 */
	@RequiresRoles(value={"admin","teacher"},logical=Logical.OR)
	@PostMapping
	public Object post(@RequestParam("file")MultipartFile file,Video video) {
		return videoService.post(file,video);
	}
	
	/**
	 * 更新视频
	 * @param video 视频字段
	 * @param file 上传文件
	 * @return 布尔值
	 */
	@RequiresRoles(value={"admin","teacher"},logical=Logical.OR)
	@PutMapping
	public Object update(MultipartFile file,Video video) {
		return videoService.update(file,video);
	}
	
	/**
	 * 删除视频
	 * @param videoIds 主键id数组
	 * @return 布尔值
	 */
	@RequiresRoles(value={"admin","manager","teacher"},logical=Logical.OR)
	@DeleteMapping("{videoIds}")
	public Object delete(@PathVariable("videoIds") int[] videoIds) {
		return videoService.delete(videoIds);
	}
	
	/**
	 * 检查名称
	 * @param name 视频名称
	 * @return 布尔值
	 */
	@RequiresRoles(value={"admin","teacher"},logical=Logical.OR)
	@GetMapping("checkName")
	public Object checkName(@RequestParam("name") String name) {
		return videoService.checkName(name);
	}
	
}
